const user = require("../../../../api/user");

// pages/mine/myIncome/detail/detail.js
const app = getApp(),
    globalData = app.globalData,
    api = require("../../../../api/index"),
    utils = require('../../../../utils/util');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        list: [],
        filter: {
            currenetPageIndex: 1,
            pageSize: 10,
            recordCount: 0
        },
        status: 0,
        toast: {
            visible: false,
            text: ''
        },
        hasMore: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.reload()
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if (this.data.hasMore) {
            this.setData({
                'filter.currenetPageIndex': ++this.data.filter.currenetPageIndex
            });

            this.getList();
        }
    },

    reload() {
        this.setData({
            status: 0,
            userInfo: wx.getStorageSync('userinfo') || {}
        })
        this.getList()
    },

    // 获取收益明细流水
    async getList() {
        wx.showLoading({
            title: '内容加载中',
        })
        let userId = wx.getStorageSync('userinfo').UserId || '',
            obj = this.data.filter;
        try {
            let res = await api.balance.getBalanceDetail(obj),
                data = res.data.ResData || {};
            console.log(res, '收入明细')
            if (this.data.filter.currenetPageIndex > 1) {
                data.Items = this.data.list.concat(data.Items);
            }
            this.setData({
                list: data.Items || [],
                hasMore: data.TotalPages == 0 ? false : data.CurrentPage == data.TotalPages ? false : true,
                status: 2
            })

        } catch (e) {
            console.log(e, '获取收入明细失败')
            this.setData({
                status: 1
            })
        } finally {
            wx.hideLoading()
        }
    }
})